<?php

namespace app\modules\home\controllers;

use Yii;
use app\controllers\ApiBaseController;
use app\modules\home\actions as actions;

class ImageController extends ApiBaseController {
    
    public function init(){
        
    }
    
    /**
     * 添加认可
     * @param  array $arrInput
     * @return
     */
    public function actionRatification() {

        $data= Yii::$app->request->get();
        if(empty($data)) {
            $data= Yii::$app->request->post();
        }
        $action = new actions\Image();
        $ret = $action->Ratification($data);
        return $ret;
    }
    
    /**
     * 添加质疑
     * @param  array $arrInput
     * @return
     */
    public function actionOppugn() {
        $data = Yii::$app->request->get();
        if(empty($data)) {
            $data = Yii::$app->request->post();
        }
        $action = new actions\Image();
        $ret = $action->Oppugn($data);
        return $ret;
    }
    
    /**
     * 添加预留联系方式
     * @param  array $arrInput
     * @return
     */
    public function actionLiaison() {
        $data = Yii::$app->request->get();
        if(empty($data)) {
            $data = Yii::$app->request->post();
        }
        $action = new actions\Image();
        $ret = $action->Liaison($data);
        return $ret;
    }
    
    /*
     * 上传图片
     */
    public function actionUpload() {
        $data = Yii::$app->request->get();
        if(empty($data)) {
            $data = Yii::$app->request->post();
        }
        $action = new actions\Image();
        $ret = $action->Upload($data);
        return $ret;
    } 
    
    /*
     * 删除图片
     */
    public function actionDel() {
        $data = Yii::$app->request->get();
        if(empty($data)) {
            $data = Yii::$app->request->post();
        }
        $action = new actions\Image();
        $ret = $action->Liaison($data);
        return $ret;
    }
    
    /**
     * 获取用户最近上传的三张图片
     */
    public function actionLastimagelist() {
        $data = Yii::$app->request->get();
        if(empty($data)) {
            $data = Yii::$app->request->post();
        }
        $action = new actions\Image();
        $ret = $action->GetLastImageList($data);
        return $ret;
    }
    
    /**
     * 删除图片
     */
    public function actionDelimage() {
        $data = Yii::$app->request->get();
        if(empty($data)) {
            $data = Yii::$app->request->post();
        }
        $action = new actions\Image();
        $ret = $action->Del($data);
        return $ret;
    }
    
    /**
     * 获取用户列表
     */
    public function actionImagelist() {
        $data = Yii::$app->request->get();
        if(empty($data)) {
            $data = Yii::$app->request->post();
        }
        $action = new actions\Image();
        $ret = $action->GetUserImageList($data);
        return $ret;
    }
    
    /**
     * 图像识别
     */
    public function actionImagerecognition() {
        $data = Yii::$app->request->get();
        if(empty($data)) {
            $data = Yii::$app->request->post();
        }
        $action = new actions\Image();
        $ret = $action->ImageRecognition($data);
        return $ret;
    }
    
    /**
     * 最新识别结果
     */
    public function actionGetlastrecognition() {
        $data = Yii::$app->request->get();
        if(empty($data)) {
            $data = Yii::$app->request->post();
        }
        $action = new actions\Image();
        $ret = $action->GetLastRecognition($data);
        return $ret;
    }
    
    /**
     * 
     */
    public function actionDownload() {
        $file = '/var/www/html/otc-fe/OCT/file/src/3.jpg';
        if(file_exists($file)) {
            header("Content-type:application/octet-stream");
            $filename = basename($file);
            header("Content-Disposition:attachment;filename = ".$filename);
            header("Accept-ranges:bytes");
            header("Accept-length:".filesize($file));
            readfile($file);
        }else{
            return '文件不存在';
        }
        
        return true;
    }
    
    public function actionClear() {
//         yii::$app->cache->del("oct|recCountRedisKey");
        $count = yii::$app->cache->get("oct|recCountRedisKey");
        return $count;
    }
}